package ipmss.ui.desktop;

import ipmss.dwr.DesktopRemoteBean;
import ipmss.entity.authorities.User;
import ipmss.entity.authorities.UserProfile;
import ipmss.entity.desktop.Desktop;
import ipmss.security.Authorities;
import ipmss.services.authorities.UsersManagementService;
import ipmss.services.common.UserContext;
import ipmss.ui.common.Messages;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.mail.MessagingException;

import org.primefaces.context.RequestContext;
import org.primefaces.event.CloseEvent;
import org.primefaces.event.FlowEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.annotation.Secured;

// TODO: Auto-generated Javadoc
/**
 * The Class DesktopViewBean.
 *
 * @author Michał Czarnik
 */
@Named
@Scope("session")
public class DesktopViewBean implements Serializable
{
    
    /** The Constant logger. */
    private static final Logger logger = Logger.getLogger(DesktopViewBean.class.getName());




    /** The desktop remote. */
    @Inject
    private DesktopRemoteBean desktopRemote;
    
    /** The user context. */
    @Inject
    private UserContext userContext;
    
    /** The selected desktop. */
    private String selectedDesktop;
    
    /** The desktops. */
    private List<String> desktops =  new ArrayList<String>();

    /** The r. */
    private Random r = new Random();

    /**
     * Gets the random boolean.
     *
     * @return the random boolean
     */
    public boolean getRandomBoolean()
    {
	return r.nextBoolean();
    }

    /**
     * Random boolean.
     *
     * @return true, if successful
     */
    public boolean randomBoolean()
    {
	return r.nextBoolean();
    }

    /**
     * Gets the b.
     *
     * @return the b
     */
    public String getB()
    {
	return "true";
    }

    // private boolean showUsersList = true;

    /**
     * Instantiates a new desktop view bean.
     */
    public DesktopViewBean()
    {
	return;

    }

  
    /**
     * Gets the test view visible.
     *
     * @return the test view visible
     */
    public boolean getTestViewVisible()
    {
	return desktopRemote.isPanelVisible("testview");
    }

    /**
     * Gets the test view2 visible.
     *
     * @return the test view2 visible
     */
    public boolean getTestView2Visible()
    {
	return desktopRemote.isPanelVisible("testview2");
    }

    /**
     * Gets the test view3 visible.
     *
     * @return the test view3 visible
     */
    public boolean getTestView3Visible()
    {
	return desktopRemote.isPanelVisible("testview3");
    }

    
    public boolean getTasksListMainViewVisible()
    {
	return desktopRemote.isPanelVisible("TasksListMainView");
    }
    
    public boolean getProjectsListMainViewVisible()
    {
	return desktopRemote.isPanelVisible("ProjectsListMainView");
    }
    
    
    /**
     * Gets the schedule main view visible.
     *
     * @return the schedule main view visible
     */
    public boolean getScheduleMainViewVisible()
    {
	return desktopRemote.isPanelVisible("ScheduleMainView");
    }
    
    /**
     * Gets the schedule details view visible.
     *
     * @return the schedule details view visible
     */
    public boolean getScheduleDetailsViewVisible()
    {
	return desktopRemote.isPanelVisible("ScheduleMainView");
    }
    
    
    /**
     * Gets the users management main view visible.
     *
     * @return the users management main view visible
     */
    public boolean getUsersManagementMainViewVisible()
    {
	return desktopRemote.isPanelVisible("UsersManagementMainView");
    }
    
    /**
     * Gets the new project main view visible.
     *
     * @return the new project main view visible
     */
    public boolean getNewProjectMainViewVisible()
    {
 	return desktopRemote.isPanelVisible("NewProjectMainView");
    }
    /*
     * public boolean isShowUsersList() { return showUsersList; }
     * 
     * public void setShowUsersList(boolean showUsersList) { this.showUsersList
     * = showUsersList; }
     */

    /**
     * Gets the selected desktop.
     *
     * @return the selected desktop
     */
    public String getSelectedDesktop()
    {
	return userContext.getCurrentView().getName();
    }

    /**
     * Sets the selected desktop.
     *
     * @param selectedDesktop the new selected desktop
     */
    public void setSelectedDesktop(String selectedDesktop)
    {
	this.selectedDesktop = selectedDesktop;
    }

    /**
     * Gets the desktops.
     *
     * @return the desktops
     */
    public List<String> getDesktops()
    {
	desktops =  new ArrayList<String>(desktops.size());
       for(Desktop d :userContext.getViews())
       {
	   desktops.add(d.getName());
       }
       return desktops;
    }

    /**
     * Sets the desktops.
     *
     * @param desktops the new desktops
     */
    public void setDesktops(List<String> desktops)
    {
	this.desktops = desktops;
    }

    /**
     * Gets the user context.
     *
     * @return the user context
     */
    public UserContext getUserContext()
    {
	return userContext;
    }

    /**
     * Sets the user context.
     *
     * @param userContext the new user context
     */
    public void setUserContext(UserContext userContext)
    {
	this.userContext = userContext;
    }
    
    
    /** The project name. */
    private String projectName;

    /**
     * Gets the project name.
     *
     * @return the project name
     */
    public String getProjectName()
    {
	return projectName;
    }

    /**
     * Sets the project name.
     *
     * @param projectName the new project name
     */
    public void setProjectName(String projectName)
    {
	this.projectName = projectName;
    }
    
    /**
     * On flow process.
     *
     * @param event the event
     * @return the string
     */
    public String onFlowProcess(FlowEvent event) {  

       
            return event.getNewStep();  
        
    }  


}
